from django.db import models


# Create your models here.
class User(models.Model):
    username = models.CharField(max_length=50, null=True)
    password = models.CharField(max_length=256, null=True)


class Goods(models.Model):
    title = models.CharField('商品名称', max_length=24)
    price = models.DecimalField('商品价格', max_digits=8, decimal_places=2)


class Orders(models.Model):
    ORDER_STATUS = (
        (1, '待支付'),
        (2, '已支付'),
        (3, '已取消'),
    )
    user = models.ForeignKey(User, on_delete=models.PROTECT, verbose_name='下单用户')
    goods = models.ForeignKey(Goods, on_delete=models.PROTECT)
    order_id = models.CharField('订单号', max_length=256)
    trade_no = models.CharField('支付宝订单号', max_length=32, null=True)  # 28位
    pay_time = models.DateTimeField('支付时间', null=True)
    status = models.CharField('支付状态', choices=ORDER_STATUS, default=1, max_length=8)
    total_amount = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='商品总金额')


class Chat(models.Model):
    name = models.CharField(max_length=50, null=False, unique=True)
    user1 = models.CharField(max_length=50, null=False)
    user2 = models.CharField(max_length=50, null=False)
    class Meta:
        unique_together = (('user1', 'user2'),)

class Message(models.Model):
    message = models.CharField(max_length=500, null=True)
    chat = models.ForeignKey(Chat, on_delete=models.CASCADE, null=False)
    sender = models.CharField(max_length=50)
class Book(models.Model):
    btitle = models.CharField(max_length=50)
    bpub_date = models.CharField(max_length=50)
    bread = models.IntegerField(default=100)
    bcomment = models.IntegerField(default=0)